<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/js/elementui/index.css">
    <style>
        .inp{
            width: 300px;
        }
    </style>
</head>
<body>
<div id="arr" style="width: 600px;margin: auto">
    <el-menu
            class="el-menu-demo"
            mode="horizontal"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b">
        <el-menu-item index="1"><a target="_blank">企业注册</a></el-menu-item>
        <el-menu-item @click="loginRegterinUser" index="4"><a target="_blank">用户注册</a></el-menu-item>
    </el-menu>
    <hr>
    <h3>企业注册</h3>
    <hr>
    <span>{{mgr}}</span>
    <el-form ref="form" :model="company" label-width="80px">
        <el-form-item label="企业名称">
            <el-input class="inp" @blur="companyNameq" v-model="company.companyName"></el-input>
            <span>{{str}}</span>
        </el-form-item>
        <el-form-item label="企业法人">
            <el-input class="inp" @blur="userNameq" v-model="company.legal"></el-input>
            <span>{{str1}}</span>
        </el-form-item>
        <el-form-item label="登录密码">
            <el-input class="inp" type="password" v-model="passWord"></el-input>
            <span>{{str3}}</span>
        </el-form-item>
        <el-form-item label="确认密码">
            <el-input class="inp" @blur="companyPsw" type="password" v-model="passWord2"></el-input>
            <span>{{str2}}</span>
        </el-form-item>
        <el-form-item label="联系方式">
            <el-input class="inp" @blur="companyLegalTel" v-model="company.legalTel"></el-input>
            <span>{{stra}}</span>
        </el-form-item>
        <el-form-item label="企业邮箱">
            <el-input class="inp" @blur="loginCompanyEmail" v-model="company.companyEmail"></el-input>
            <span>{{strb}}</span>
        </el-form-item>
        <el-form-item label="经营范围">
            <el-select v-model="company.businessScope" placeholder="请选择活动区域">
                <el-option label="科技" value="科技"></el-option>
                <el-option label="信息技术" value="信息技术"></el-option>
                <el-option label="游戏" value="游戏"></el-option>
                <el-option label="电子" value="电子"></el-option>
                <el-option label="软件" value="软件"></el-option>
                <el-option label="人力资源" value="人力资源"></el-option>
                <el-option label="生物科技" value="生物科技"></el-option>
                <el-option label="投资管理" value="投资管理"></el-option>
                <el-option label="实业" value="实业"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit">立即注册</el-button>
            <el-button @click="loginLog">取消</el-button>
        </el-form-item>
    </el-form>
</div>

</body>
<script src="/js/vue/vue.js"></script>
<script src="/js/axios/axios.min.js"></script>
<script src="/js/qs/qs.min.js"></script>
<script src="/js/elementui/index.js"></script>
<script>
    new Vue({
        el: '#arr',
        data() {
            return {
                company: {
                    companyName: '',
                    legal: '',
                    legalTel: '',
                    companyEmail: '',
                    businessScope: '',
                },
                user:{
                    userName:'',
                    passWord: '',
                    realName:'',
                    userEmail:'',
                    userTel:'',
                    companyId:''
                },
                passWord: '',
                passWord2: '',
                str: '',
                str1: '',
                str2: '',
                str3: '',
                stra: '',
                strb: '',
                mgr: ''

            }
        },
        methods: {
            onSubmit() {
                if (this.company.companyName!=''&&this.company.legalTel!=''&&this.company.companyEmail!=''&&this.businessScope!=''&&this.passWord!=''){
                    console.log('submit!');
                    this.companyRegisterin1()
                }else {
                    this.mgr="输入值有误！"
                }

            },
            loginRegterinUser() {
                location.href = "/registerin/registerin-user.html"
            },
            loginLog() {
                location.href = "/login.html"
            },
            companyNameq() {
                if (this.company.companyName!=''){
                    axios.get("/comuser/companyName1/" + this.company.companyName).then(value => {
                        this.str=value.data
                    });
                }else {
                    this.str="该字段必须填写！"
                }

            },
            userNameq(){
                if (this.company.legal!=''){
                    axios.get("/comuser/userName1/"+this.company.legal).then(value => {
                       this.str1=value.data
                    });
                }else {
                    this.str1='该字段必须填写!'
                }
            },
            companyPsw(){
                if (this.passWord2!=''){
                    if (this.passWord2!=''&&this.passWord!=''){
                        if (this.passWord==this.passWord2){
                            this.str2="正常"
                        }else {
                            this.str2="前后密码不一致"
                        }
                    }else {
                        this.str2="该字段必须填写!"
                    }
                }else {
                  this.str3="该字段必须填写!"
                }

            },
            companyLegalTel(){
                if (this.company.legalTel==''){
                    this.stra="该字段必须填写!"
                }else {
                    this.stra="正常"
                }

            },
            loginCompanyEmail(){
                if (this.company.companyEmail==''){
                    this.strb="该字段必须填写!"
                }else {
                    this.strb="正常"
                }
            },
            companyRegisterin1(){
                axios.post("/comuser/company",this.company).then(value => {
                    this.user.companyId=value.data
                    this.userReqistern()
                })
            },
            userReqistern(){
                this.user.userName=this.company.companyName
                this.user.passWord=this.passWord2
                this.user.userEmail=this.company.companyEmail
                this.user.realName=this.company.companyName
                this.user.userTel=this.company.legalTel
                axios.post("/comuser/user",this.user).then(value => {
                    this.loginLog()
                })
            }
        }
    })
</script>

</html>